import com.atguigu.realtime.bean.StartupLog
import org.json4s.JValue
import org.json4s.JsonAST.JObject
import org.json4s.jackson.JsonMethods

/**
 * Author atguigu
 * Date 2020/11/10 11:22
 */
object Json4sDemo {
    def main(args: Array[String]): Unit = {
        /*val json =
            """
              |{"name": "李四", "age": 20}
              |""".stripMargin
    
        val jValue: JValue = JsonMethods.parse(json)
    
        /*val name: JValue = jValue \ "name"
        implicit val f = org.json4s.DefaultFormats
        /*val s= name.extract[Int]*/
        println(s)*/
        implicit val f = org.json4s.DefaultFormats
        val user: User = jValue.extract[User]
        println(user)*/
       val  jsonString =
           """
             |{
             |    "common":{
             |        "ar":"440000",
             |        "ba":"iPhone",
             |        "ch":"Appstore",
             |        "md":"iPhone X",
             |        "mid":"mid_26",
             |        "os":"iOS 13.2.9",
             |        "uid":"477",
             |        "vc":"v2.1.134"
             |    },
             |    "start":{
             |        "entry":"icon",
             |        "loading_time":1925,
             |        "open_ad_id":6,
             |        "open_ad_ms":8828,
             |        "open_ad_skip_ms":1129
             |    },
             |    "ts":1597319770000
             |}
             |""".stripMargin
    
        val value: JValue = JsonMethods.parse(jsonString)
        val jCommon: JValue = value \ "common"
        
        val jTs: JValue = value \ "ts"
        implicit val f = org.json4s.DefaultFormats
        val o = jCommon.merge(JObject("ts" -> jTs)).extract[StartupLog]
        println(o)
        
    }
}
case class User(name: String, age: Int)
